package com.meilai.project.controller.web.business.offer;


import com.meilai.project.dto.CommonResult;
import com.meilai.project.dto.base.ApiResult;
import com.meilai.project.entity.business.offer.Offer;
import com.meilai.project.service.business.offer.OfferService;
import com.meilai.project.vo.business.offer.OfferQueryVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 报价表 前端控制器
 * </p>
 *
 * @author xhy
 * @since 2022-01-11
 */
@RestController
@RequestMapping("api/web/offer")
public class OfferController {

    @Autowired
    private OfferService service;

    @GetMapping("/page")
    @ApiOperation("查询列表")
    public CommonResult page(@RequestParam(name = "industry_id", required = false) Long industry_id) {
        return new CommonResult().success(service.page(industry_id));
    }

    @GetMapping("/getMediaList")
    @ApiOperation("获取媒体信息")
    public CommonResult getMediaList() {
        return new CommonResult().success(service.getMediaList());
    }

    @GetMapping("/list")
    @ApiOperation("查询所有刊例总价")
    public CommonResult getOfferList(@RequestParam(name = "mediaTypeId", required = false) Long mediaTypeId,
                                     @RequestParam(name = "is_media", required = false) Integer is_media) {
        return new CommonResult().success(service.getOfferList(mediaTypeId, is_media));
    }

    @PostMapping("/edit")
    @ApiOperation("修改刊例总价")
    public CommonResult edit(@RequestBody Offer offer) {
        return new CommonResult().success(service.edit(offer));
    }

    @PostMapping("/settings/redLinePrice")
    @ApiOperation("设置红线价")
    public ApiResult<Boolean> settingsRedLinePrice(@RequestParam("industry_id") Long industry_id, @RequestParam("media_type_spec_id") Long media_type_spec_id,
                                                   @RequestParam("red_line_price") BigDecimal red_line_price) {
        return ApiResult.ok(service.settingsRedLinePrice(industry_id, media_type_spec_id, red_line_price));
    }

    @GetMapping("/query")
    @ApiOperation("报价查询")
    public ApiResult<List<OfferQueryVO>> query(@RequestParam("industry_id") Long industry_id) {
        return ApiResult.ok(service.queryByIndustryId(industry_id));
    }
}

